package vip.liux.contracts.models.identity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.Persistable;

/**
 * 用户的身份验证令牌
 */

@Getter
@Setter
@Entity
@Table(name = "identity_user_tokens")
public class IdentityUserToken implements Persistable<IdentityUserTokenId> {
    @EmbeddedId
    private IdentityUserTokenId id;

    @ManyToOne
    @JoinColumn(name = "user_id", insertable = false, updatable = false)
    private IdentityUser user;

    /**
     * 租户ID
     */
    @Column(name = "tenant_id", length = 36)
    private String tenantId;

    /**
     * 令牌
     */
    @Column(name = "value")
    private String value;

    @JsonIgnore
    @Transient
    @Override
    public boolean isNew() {
        return id == null;
    }
}